<template>
	<view>
		<uni-popup ref="popup" type="center" @change="popChange">
			<view class="parent-view">
				<text class="title-txt">开通功德榜</text>
				<view class="jiapu-input-view">
					<input class="jiapu-input" placeholder="请输入家谱ID" @input="onKeyInput"/>
					<text class="jiapu-search" @click="search">搜索</text>
				</view>
				<view class="jiapu-info-view" v-if="jiapuData.title">
					<text class="jiapu-name">{{jiapuData.title}}</text>
					<text class="jiapu-bianjiren">主编人：{{jiapuData.uname}}</text>
				</view>
				<text class="jiapu-tip" v-if="jiapuData.title">“{{jiapuData.uname}}”可在家谱权限管理设置财务</text>
				<view class="btn-view">
					<text class="btn-cancle" @click="clickLeft">取消</text>
					<text class="btn-sure" @click="clickRight">确认</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import request from '../../pages/index/request.js';
	
	export default {
		name: "open-merit-list-pop",
		props: {
			isShow: false,
			dataSource: String,
		},
		watch: {
			isShow(val) {
				if (val) {
					this.jpmuseumid=this.$props.dataSource
					this.$refs.popup.open();
				}
			}
		},
		data() {
			return {
				inputKey:"",
				jpmuseumid:"",
				jiapuData:{}
			};
		},
		methods: {
			onKeyInput: function(event) {
				this.inputKey = event.target.value
			},
			popChange:function(e) {
				if (!e.show) {
					var obj = {
						isclose: false,
					};
					this.$emit('returnOpenMeritDialog', obj);
				}
			},
			search:function(){
				if(this.inputKey){
					this.searchPedigreeInfo()
				}else{
					uni.showToast({
						title:"请输入家谱ID",
						icon:"none"
					})
				}
			},
			clickLeft:function() {
				var obj = {
					isclose: false,
				};
				this.$emit('returnOpenMeritDialog', obj);
				this.$refs.popup.close();
			},
			clickRight:function() {
				if(this.jiapuData.coding){
					this.openPedigreeFinance()
				}else{
					uni.showToast({
						title:"请搜索家谱ID",
						icon:"none"
					})
				}
			},
			searchPedigreeInfo: function() {
				var that = this
				request.post("api/common/SearchPedigreeInfo", {
					jpmuseumid:this.jpmuseumid,
					jpcode:this.inputKey
				}).then(data => {
					that.jiapuData=data
				})
			},
			openPedigreeFinance: function() {
				var that = this
				request.post("api/common/OpenPedigreeFinance", {
					jpmuseumid:this.jpmuseumid,
					jpcode:this.jiapuData.coding
				}).then(data => {
					var obj = {
						isclose: false,
						tag: "sure"
					};
					that.$emit('returnOpenMeritDialog', obj);
					that.$refs.popup.close();
				})
			},
		}
	}
</script>

<style>
	@import "open-merit-list-pop.css";
</style>
